<?php
/**
 * 模块视图渲染类
 *
 * @author Mo yi <root@imoi.cn>
 * @link   http://www.imoi.cn
 * @copyright Copyright &copy; 2010-2012 DuoLam Software LLC
 * @license http://www.imoi.cn/license/
 * @version $Id: dpModuleRender.php 1 2012-04-04 09:31:13Z Mo.yi $
 * @package view.renders
 * @since 1.0
 */

class dpModuleRender extends dpView implements IView
{
	/**
	 * 设置模块载入文件基准地址，并注册系统标签
	 */
	public function setFilePath()
	{
		$path = explode(ROOT,str_replace('\\','/',$this->getViewPath()));
		$path = ROOT == '/' ? $this->getCtrlViewPath() : ROOT . $path[1];
		$this->setLoadFilePath($path);
		$this->systemTags();
	}

	/**
	 * 渲染视图
	 * @param string  $viewFile 视图文件名
	 * @param array   $var      注入模板的变量
	 * @param boolean $return   是否返回模板内容
	 */
	function render($viewFile = '', $var = array(), $return = false)
	{
		if ($this->getThemePath()) {
			$this->setViewPath($this->getThemePath());
			$this->setCtrlViewPath(ROOT . 'themes' . DS . $this->getTheme());
		} else
			$this->setViewPath(APP_PATH . $this->getCtrlViewPath());

		$this->setFilePath();
		$file = $this->getThemePath() ?
				$this->getThemePath() . $viewFile . $this->getSuffix() : 
				$this->getViewPath()  . $viewFile . $this->getSuffix();
		$content = parent::render($file, $var);

		if ($return)
			return $content;
		else
			echo $content;
	}
}